package com.gimi.cloud.bbp.manage.consumer.service.sys.impl;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.sys.SysMasterDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.SystemFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.sys.SysMasterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 管理员相关接口实现类
 * @author wbj
 * @version 1.0
 * @Description
 * @create 2018-01-26
 **/
@Service
public class SysMasterServiceImpl implements SysMasterService{
    private static final Logger logger = LoggerFactory.getLogger(SysMasterServiceImpl.class);
    private SystemFeignService systemFeignService;

    @Autowired
    public SysMasterServiceImpl(SystemFeignService systemFeignService) {
        this.systemFeignService = systemFeignService;
    }

    @Override
    public Response getMasterList(HttpServletRequest request, HttpServletResponse response, SysMasterDTO dto) throws Exception {
        return systemFeignService.getMasterList(dto);
    }

    @Override
    public Response getMasterInfo(HttpServletRequest request, HttpServletResponse response, SysMasterDTO masterDTO) throws Exception {
        if(null == masterDTO.getMaId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"管理员id为空，获取管理员信息失败");
            return resp;
        }
        return systemFeignService.getMasterInfo(masterDTO);
    }

    @Override
    public Response addMaster(HttpServletRequest request, HttpServletResponse response, SysMasterDTO masterDTO) throws Exception {
        if(null != masterDTO.getMaId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"管理员Id不为空，添加管理员信息失败");
            return resp;
        }
        return systemFeignService.saveMaster(masterDTO);
    }

    @Override
    public Response editMaster(HttpServletRequest request, HttpServletResponse response, SysMasterDTO masterDTO) throws Exception {
        if(null == masterDTO.getMaId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"管理员Id为空，修改管理员信息失败");
            return resp;
        }
        return systemFeignService.saveMaster(masterDTO);
    }

    @Override
    public Response deleteMaster(HttpServletRequest request, HttpServletResponse response, SysMasterDTO masterDTO) throws Exception {
        if(null == masterDTO.getMaId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"管理员Id为空，删除管理员信息失败");
            return resp;
        }
        return systemFeignService.deleteMaster(masterDTO);
    }
}
